package com.dinggao.crossgo.module.roadbook.adapter;

import android.net.Uri;
import android.support.annotation.NonNull;
import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.dinggao.crossgo.R;
import com.dinggao.crossgo.core.observer.EventIntet;
import com.dinggao.crossgo.core.observer.EventMsg;
import com.github.chrisbanes.photoview.OnPhotoTapListener;
import com.github.chrisbanes.photoview.PhotoView;

import java.util.List;

/**
 * created by mapingan on 2018/8/9.
 */
public class SamplePagerAdapter extends PagerAdapter {

    private List<String> image;




    public SamplePagerAdapter(List<String> image) {
        this.image = image;
    }

    @Override
    public int getCount() {
        return image.size();
    }

    @Override
    public View instantiateItem(final ViewGroup container, int position) {
        PhotoView photoView = new PhotoView(container.getContext());


        Glide.with(container.getContext())
                .load(image.get(position))
                .apply(new RequestOptions()
                .placeholder(R.drawable.sublist_image).error(R.drawable.sublist_image)).into(photoView);

        // Now just add PhotoView to ViewPager and return it
        container.addView(photoView, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);


        photoView.setOnPhotoTapListener(new OnPhotoTapListener() {
            @Override
            public void onPhotoTap(ImageView view, float x, float y) {
                EventIntet.getDefault().post(new EventMsg("SamplePagerAdapter--finish",10086, String.valueOf(getClass().getName())));
            }
        });

        return photoView;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView((View) object);
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }



}
